package geom;

import java.util.List;

/**
 * Responsible for modeling two dimensional vectors
 * @author Peter Zastoupil, peterzastoupil@gmail.com
 *
 */
public class Vector {
	
	/**
	 * Represents the component x & y vectors of the Vector object
	 */
	Point components = null;
	
	/**
	 * Default constructor for the Vector class; contructs a Vector with (0,0) component vectors
	 */
	Vector(){
		this.clearVector();
	}
	
	/**
	 * Constructs a Vector with the same components vectors as a given Vector
	 * @param v is the Vector whose components are copied
	 */
	Vector(Vector v){
		this.components = v.getComponentVectors();
	}
	
	/**
	 * Constructs a Vector from a given {@link Point}, representing the x & y component vectors
	 * @param components is the {@link Point} representing the x & y component vectors
	 */
	Vector(Point components){
		this.components = components;
	}
	
	/**
	 * Constructs a Vector from two given component Vectors
	 * @param x represents the component vector along the x axis
	 * @param y represents the component vector along the y axis
	 */
	Vector(double x, double y){
		this.components = new Point(x, y);
	}
	
	/**
	 * Constructs a Vector composite of a given list of Vectors
	 * @param vectorList is the list of Vectors to be added together to create the new Vector
	 */
	Vector(List<Vector> vectorList){
		this.clearVector();
		this.addVectorList(vectorList);
		
	}
	
	/**
	 * Sets the component vectors of the Vector object to the values of a given {@link Point}
	 * @param components is the point
	 */
	void setComponentVectors(Point components){
		this.components = components;
	}
	
	/**
	 * Returns the component vectors of the Vector object as a {@link Point} object
	 * @return the component vectors
	 */
	Point getComponentVectors(){
		return this.components;
	}
	
	/**
	 * Sets the component vector along the x axis to a given value
	 * @param x is the new value of the component vector
	 */
	void setXComponent(double x){
		this.components.setX(x);
	}
	
	/**
	 * Returns the magnitude of the component vector along the x axis
	 * @return the magnitude of the component vector
	 */
	double getXComponent(){
		return this.components.getX();
	}
	
	/**
	 * Sets the component vector along the y axis to a given value
	 * @param y is the new value of the component vector
	 */
	void setYComponent(double y){
		this.components.setY(y);
	}
	
	/**
	 * Returns the magnitude of the component vector along the y axis
	 * @return the magnitude of the component vector
	 */
	double getYComponent(){
		return this.components.getY();
	}
	
	/**
	 * Sets the component vectors of the Vector object to (0,0)
	 */
	void clearVector(){
		this.components = new Point(0, 0);
	}
	
	/**
	 * Adds a given Vector to this Vector
	 * @param v is the Vector to be added
	 */
	void addVector(Vector v){
		this.setXComponent(this.getXComponent() + v.getXComponent());
		this.setYComponent(this.getYComponent() + v.getYComponent());
	}
	
	/**
	 * Adds a list of Vectors to this Vector
	 * @param vectorList is the list of Vectors to be added
	 */
	void addVectorList(List<Vector> vectorList){
		for(Vector v : vectorList){
			this.addVector(v);
		}
	}

}
